<template>
  <div class="goods-list">
    <div class="goods-item" v-for="item in goodsList" :key="item.id" @click="goDataLi(item.id)">
      <img :src="item.img_url" alt />
      <h4>{{ item.title }}</h4>
      <div class="subtitle">
        <p>
          <span class="now">￥{{ item.sell_price }}</span>
          <span class="old">￥{{ item.market_price }}</span>
        </p>
        <p class="rmz">
          <span>热卖中</span>
          <span>剩{{ item.stock_quantity }}件</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      pageindex: 1,
      goodsList: []
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.$http
        .get("api/getgoods?pageindex=" + this.pageindex)
        .then(result => {
          if (result.data.status === 0) {
            this.goodsList = this.goodsList.concat(result.data.message);
          }
        });
    },
    goDataLi(id) {
      this.$router.push({ name: "goodsInfo", params: { id } });
    }
  }
};
</script>
<style lang="scss" scope>
.goods-list {
  padding: 4px;
  flex-wrap: wrap;
  display: flex;
  justify-content: space-between;
  .goods-item {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 49%;
    padding: 2px;
    border: 1px solid #ccc;
    box-shadow: 0 0 5px #ccc;
    margin: 7px 0;
    min-height: 300px;
    img {
      width: 100%;
    }
    .subtitle {
      background-color: #eee;
      padding: 3px 0;
      p {
        margin: 3px 0 0 0;
        .now {
          font-size: 16px;
          color: red;
        }
        .old {
          font-size: 12px;
          text-decoration: line-through;
          margin-left: 5px;
        }
      }
      .rmz {
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>